package com.zxy.ziems.server.device.controller;

import com.zxy.ziems.server.device.pojo.dto.ChannelDeviceDTO;
import com.zxy.ziems.server.device.pojo.vo.ChannelDeviceVO;
import com.zxy.ziems.server.device.service.ChannelDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集管理-通信通道管理设备
 * @author 10348359
 * @create 2024-03-26 14:31
 */
@RestController
@Validated
@RequestMapping("/api")
public class ChannelDeviceController {

    /**
     * 新增设备
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/device/channel/add")
    public void add(@Validated(value = ChannelDeviceDTO.Add.class) @RequestBody ChannelDeviceDTO<Object> dto) throws Exception {
        service.add(dto);
    }

    /**
     * 更新设备
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/device/channel/update")
    public void update(@Validated(value = ChannelDeviceDTO.Update.class) @RequestBody ChannelDeviceDTO<Object> dto) throws Exception {
        service.update(dto);
    }

    /**
     * 删除设备
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/device/channel/delete")
    public void delete(@Validated(value = ChannelDeviceDTO.Delete.class) @RequestBody ChannelDeviceDTO<Object> dto) throws Exception {
        service.deleteById(dto.getId());
    }

    /**
     * 根据设备id 查询该通道下的设备详情 其中自定义部分见advanced部分
     * @param id id
     * @return
     */
    @GetMapping("/device/collector/device/channel/detail")
    public ChannelDeviceVO<Object> detail(String id) throws Exception {
        return service.detailById(id);
    }

    /**
     * 根据通信通道id 查询全部设备列表
     * @param channelId 通信通道Id
     * @return
     */
    @GetMapping("/device/collector/device/channel/list")
    public List<ChannelDeviceVO<Object>> list(String channelId) throws Exception {
        return service.listByChannelId(channelId);
    }

    private ChannelDeviceService service;

    @Autowired
    public void setService(ChannelDeviceService channelDeviceService) {
        this.service = channelDeviceService;
    }

}
